package ioParation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelParation implements IoParation{
    public void work(BookList bookList){

        System.out.println("正在删除图书中。。。。。");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要删除书本的名字");
        String name = scanner.nextLine();
        int cuurentSized = bookList.getUsedSized();
        //1.找到要删除的书本
        int pos = -1;
        for (int i = 0; i <cuurentSized ; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                pos = i;
                break;
            }
            if(i == cuurentSized){
                System.out.println("没有找到要删除的书本");
                break;
            }
        }
        for (int j = pos; j <cuurentSized-1 ; j++) {
            //book[j] = book[j+1]
            Book book =bookList.getBook(j+1);
            bookList.setBook(j,book);
        }
        //将转移项其置空
        bookList.setBook(cuurentSized-1,null);
        //书本在数组的长度-1
        bookList.setUsedSized(cuurentSized-1);


}
}
